//
//  UIImage+Extend.m
//  CFFinanceProject
//
//  Created by chunfeng on 2018/4/9.
//  Copyright © 2018年 xiaowen. All rights reserved.
//

#import "UIImage+Extend.h"


#import <objc/message.h>


@implementation UIImage (Extend)

+ (UIImage *)imageWithOriginImage:(UIImage *)image scale :(CGFloat)scale
{
    CGSize imageSize = image.size;
    CGSize scaleSize = CGSizeMake(imageSize.width * scale, imageSize.height *scale);
    
    // Create a graphics image context
    UIGraphicsBeginImageContext(scaleSize);
    
    // new size
    [image drawInRect:CGRectMake(0,0,scaleSize.width,scaleSize.height)];
    
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // End the context
    UIGraphicsEndImageContext();
    
    // Return the new image.
    return newImage;
}

+(void)load{
    
    Method imageNamedMethod = class_getClassMethod(self,@selector(imageNamed:));
    Method yp_imageNamedMethod =  class_getClassMethod(self,@selector(lkl_imageName:));
    
    method_exchangeImplementations(imageNamedMethod, yp_imageNamedMethod);
}

+(UIImage *)lkl_imageName:(NSString *)name{
    
    UIImage * image = [UIImage lkl_imageName:name];
    if (image == nil) {NSLog(@"图片名%@的图片加载失败",name);}
    return image;
}

+ (UIImage *)lkl_ImageWithColor:(UIColor *)color size:(CGSize)size{
    
    UIGraphicsBeginImageContextWithOptions(size, 0, [UIScreen mainScreen].scale);
    [color set];
    UIRectFill(CGRectMake(0, 0, size.width, size.height));
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}


+ (UIImage *)lkl_ImageWithColor:(UIColor *)color{
    CGSize imageSize = CGSizeMake(50, 50);
    return [UIImage lkl_ImageWithColor: color size: imageSize];
}

@end
